package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * NursingProjectServiceImpl 是 NursingProjectService的实现类
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    /**
     * 护理项目分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        //调用mapper方法
        Page<NursingProjectVo> byPage = nursingProjectMapper.getByPage(name, status);
        //PageResponse.of类型转换
        return PageResponse.of(byPage,NursingProjectVo.class);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     */
    @Override
    public void caretProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * 根据id查询护理
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.getById(id);
        return BeanUtil.toBean(nursingProject,NursingProjectVo.class);
    }

    /**
     * 编辑护理项目
     * @param nursingProjectDto
     */
    @Override
    public void updateProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 删除项目
     * @param id
     */
    @Override
    public void deleteProject(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    /**
     * 获取全部项目信息
     * @return
     */
    @Override
    public Object getByAllId() {
        return nursingProjectMapper.getAll();
    }

    /**
     * 状态启用禁用
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.status(id,status);
    }
}